
#include "InfoDisplayerComponent.h"
#include "Game\GameTime.h"
#include "Game\Game.h"
#include "Maths/Vector2.h"
#include <vector>
#include <string>
#include "Graphics/GraphicString.h"
#include "Graphics/Color.h"
#include "Game/DrawableGameComponent.h"

using namespace CasaEngine;

InfoDisplayerComponent::InfoDisplayerComponent(Game* pGame_) :
	DrawableGameComponent(pGame_)
{
}


InfoDisplayerComponent::~InfoDisplayerComponent()
{

}

void InfoDisplayerComponent::Initialize()
{
	
}

void InfoDisplayerComponent::OnLoadContent()
{

}

void InfoDisplayerComponent::Update(const GameTime& /*gameTime_*/)
{
	
}

void InfoDisplayerComponent::Draw()
{
	const int fontHeight = 16;
	std::vector<InfoData>::const_reverse_iterator it;
	CasaEngine::Vector2I pos(5, 5);

	Matrix4 m_MatProj2D, m_MatView2D;
	m_MatProj2D.OrthoOffCenter(0, 0, 640, 480);
	m_MatView2D.Identity();

	//Renderer.LoadMatrix(MatrixType::ModelView,  m_MatView2D);
	//Renderer.LoadMatrix(MatrixType::Projection, m_MatProj2D);	

	for (it = m_Lines.crbegin(); it != m_Lines.crend(); it++)
	{
		GraphicString txt(
			pos, (*it).txt, 
			(*it).color,
			"Fontdinerdotcom Huggable",
			fontHeight);

		txt.Draw(m_MatProj2D);

		pos.y += fontHeight + 5;
	}
}

void InfoDisplayerComponent::AddLine( CColor color_, std::string txt_ )
{
	InfoData data;
	std::ostringstream msg;
	msg << (m_Lines.size() + 1) << " - " << txt_;
	data.txt = msg.str();
	data.color = color_;

	m_Lines.push_back(data);
}
